package com.yhd.controller;

import com.yhd.entity.dto.CourseBookedDto;
import com.yhd.entity.dto.CourseDto;
import com.yhd.entity.dto.CourseScheduleDetailDto;
import com.yhd.entity.query.CourseBookedVO;
import com.yhd.entity.query.CourseScheduleDetailVO;
import com.yhd.entity.query.CourseVO;
import com.yhd.entity.result.ResultVo;
import com.yhd.model.ResultPage;
import com.yhd.service.CourseBookedService;
import com.yhd.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(value = "订单管理")
@Slf4j
@RequestMapping(value = "/order")
@CrossOrigin
public class OrderController extends WebBaseController {

    @Autowired
    private CourseBookedService courseBookedService;



    @ApiOperation(value = "获取课程/活动订单列表", notes = "获取课程/活动订单列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型 activity:活动，course:课程", required = true, paramType = "字符串"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, paramType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, paramType = "int")})
    @GetMapping("/list")
    @ResponseBody
    public ResultVo<ResultPage<List<CourseBookedDto>>> selectCourseBookedList(CourseBookedVO courseBookedVO){
        ResultPage<List<CourseBookedDto>> resultPage = courseBookedService.selectCourseBookedList(courseBookedVO);
        return ResultVo.success(resultPage);
    }

    @ApiOperation(value = "获取课程/活动订单详情", notes = "获取课程/活动订单详情")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "订单id", required = true, paramType = "字符串")})
    @GetMapping("/info")
    @ResponseBody
    public ResultVo<CourseBookedDto> selectCourseBookedInfo(CourseBookedVO courseBookedVO){
        CourseBookedDto courseBookedDto = courseBookedService.selectCourseBookedInfo(courseBookedVO);
        return ResultVo.success(courseBookedDto);
    }


    @ApiOperation(value = "修改订单状态", httpMethod = "PUT", notes = "{\n" +
            "  \"id\": \"订单id 必填\",\n" +
            "  \"status\": \"订单状态：1:待付款(同意报名) 3:拒绝报名 4取消订单\",\n" +
            "  \"payType\": \"支付方式：0线下支付 1线上支付\",\n" +
            "  \"participate\": \"是否允许继续参与课程/活动（已支付拒绝）：0否\"\n" +
            "}")
    @PutMapping("/putOrder")
    @ResponseBody
    public ResultVo<CourseBookedDto> putCourseBooked(@RequestBody CourseBookedVO courseBookedVO) {
        ResultVo<CourseBookedDto> resultVo = courseBookedService.putCourseBooked(courseBookedVO, getUserInfo(request));
        if (null != resultVo){
            return resultVo;
        }
        return ResultVo.failure("10003","操作失败。");
    }


}
